home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 June / EnigmA AMIGA RUN 08 (1996)(G.R. Edizioni)(IT)[!][issue 1996-06][EARSAN CD VII].iso / earcd / utmisc1 / chktex.lha / chktex / ChkTeX.h < prev    next >
C/C++ Source or Header  |  1996-04-30  |  15KB  |  566 lines

  1. /*
  2.  *  ChkTeX v1.4, header file for main program.
  3.  *  Copyright (C) 1995-96 Jens T. Berger Thielemann
  4.  *
  5.  *  This program is free software; you can redistribute it and/or modify
  6.  *  it under the terms of the GNU General Public License as published by
  7.  *  the Free Software Foundation; either version 2 of the License, or
  8.  *  (at your option) any later version.
  9.  *
  10.  *  This program is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  *  GNU General Public License for more details.
  14.  *
  15.  *  You should have received a copy of the GNU General Public License
  16.  *  along with this program; if not, write to the Free Software
  17.  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  *
  19.  *  Contact the author at:
  20.  *              Jens Berger
  21.  *              Spektrumvn. 4
  22.  *              N-0666 Oslo
  23.  *              Norway
  24.  *              E-mail: <jensthi@ifi.uio.no>
  25.  *
  26.  *
  27.  */
  28.  
  29. /********************************************************************/
  30. /**************** START OF USER SETTABLE PREFERENCES ****************/
  31.  
  32. /*
  33.  * Note: This file contains most defines you'll wish to change if you
  34.  * wish to adopt ChkTeX to a new system. It is, as you might notice,
  35.  * heavily documented. If you wish to get into the internals of ChkTeX,
  36.  * the interesting stuff is at the bottom of this file, and in the .c
  37.  * files. However, you should also take a look at the "config.h.in" file 
  38.  * in this directory if you haven't got a shell able to run the "configure"
  39.  * script.
  40.  * 
  41.  * This program relies heavily on that the system which
  42.  * automagically free()'s all malloc()'ed memory, works. The program
  43.  * itself does not call free() very much. This is because we're doing
  44.  * lots of tiny allocations, and a properly designed pooling system will
  45.  * hopefully do a quicker job than we'll be able to do. So there.
  46.  *
  47.  * To keep things simple, we trust that the fclose()'ing of fopen()'ed
  48.  * also happens automagically.
  49.  *
  50.  * Please use the getopt included, as we will modify optarg during
  51.  * command processing.
  52.  *
  53.  * You may wish to modify the SetupVars() (OpSys.c) to better suit your
  54.  * preferences. In any case, it should put the filename (and full path)
  55.  * of the `.chktexrc' file into the ConfigFile array. The array is sized
  56.  * BUFSIZ bytes.
  57.  *
  58.  * The program does also assume that AMIGA is defined if the source
  59.  * compiled on an Amiga machine, and that __unix__ is defined if the
  60.  * source is compiled on a UNIX machine.
  61.  *
  62.  */
  63.  
  64.  
  65. /*  -=><=- -=><=- -=><=- -=><=- -=><=- -=><=- -=><=- -=><=- -=><=-  */
  66.  
  67. /*
  68.  * Here you should define what codes which should be returned to the
  69.  * shell upon success/failure.
  70.  *
  71.  */
  72.  
  73. #ifndef EXIT_FAILURE
  74. #   ifdef  AMIGA
  75. #       define  EXIT_FAILURE    20
  76. #   else
  77. #       define  EXIT_FAILURE    1
  78. #   endif
  79. #endif
  80.  
  81. #ifndef EXIT_SUCCESS
  82. #   define  EXIT_SUCCESS    0
  83. #endif
  84.  
  85. /*  -=><=- -=><=- -=><=- -=><=- -=><=- -=><=- -=><=- -=><=- -=><=-  */
  86.  
  87. /*
  88.  * SLASH should be defined to the character your computer uses to
  89.  * separate files/directories. Most systems use '/', messydos uses
  90.  * '\'.
  91.  *
  92.  * DIRCHARS should be defined to the characters a directory entry
  93.  * may end on. On Amigas, this is ":/" (either "FOO:BAR/" or "FOO:"),
  94.  * Unix uses only "/", while messydos uses ":\\".
  95.  *
  96.  * This data will be used to automatically concatenate a directory
  97.  * path and a filename.
  98.  *
  99.  * Adjust both to suit your needs.
  100.  */
  101.  
  102.  
  103. #if defined(__unix__) || defined(AMIGA)
  104. #   define  SLASH           '/'
  105. #elif defined(__MSDOS__)
  106. #   define SLASH '\\'
  107. #endif
  108.  
  109. #if defined(__unix__)
  110. #   define DIRCHARS "/"
  111. #elif defined(AMIGA)
  112. #   define DIRCHARS ":/"
  113. #elif defined(__MSDOS__)
  114. #   define DIRCHARS ":\\"
  115. #endif
  116.  
  117. /*  -=><=- -=><=- -=><=- -=><=- -=><=- -=><=- -=><=- -=><=- -=><=-  */
  118.  
  119. /*
  120.  * Here, define what key-combination which is used to abort stdin
  121.  * keyboard input. It should be a string, as we we'll type it out as
  122.  * information to the user.
  123.  */
  124.  
  125. #ifdef AMIGA
  126. #    define STDIN_BREAK "Ctrl-\\"
  127. #elif defined(__unix__)
  128. #    define STDIN_BREAK "Ctrl-D"
  129. #elif defined(__MSDOS__)
  130. #    define STDIN_BREAK "Ctrl-Z + Enter"
  131. #else
  132. #    define STDIN_BREAK "stdin break combination"
  133. #endif
  134.  
  135. /*  -=><=- -=><=- -=><=- -=><=- -=><=- -=><=- -=><=- -=><=- -=><=-  */
  136.  
  137. /*
  138.  * For fancy printing of commands, we'll use these strings to turn
  139.  * on/off the error indication. The codes listed here are ANSI
  140.  * compatible; if you don't have that type of terminal, you may wish
  141.  * to adjust this. Use "chktex -v2 Test.tex" to check the effects of
  142.  * these macros. Note: These strings will be printf()'ed, so watch your
  143.  * %'s.
  144.  *
  145.  * On VT10[02] terminals, these values will be ignored; we'll use
  146.  * the sequence "_\b%c" for each character instead.
  147.  *
  148.  * PRE_ERROR_STR is of course printed in front of each location we
  149.  * wish to show as an error, and POST_ERROR_STR after each location.
  150.  *
  151.  * The codes #defined here, will switch back- and foreground colours.
  152.  * We're using '\033[' as escape character, some terminals may like
  153.  * '\233' better.
  154.  *
  155.  */
  156.  
  157. #define PRE_ERROR_STR   "\033[7m"
  158. #define POST_ERROR_STR  "\033[0m"
  159.  
  160. /*  -=><=- -=><=- -=><=- -=><=- -=><=- -=><=- -=><=- -=><=- -=><=-  */
  161.  
  162. /*
  163.  * The next macro should contain a list of characters LaTeX (and you?)
  164.  * considers as an end-of-sentence characters, which should be
  165.  * detected when whether sentence spacing is correct.
  166.  *
  167.  */
  168.  
  169. #define LATEX_PUNCT             ".:?!"
  170.  
  171.  
  172. /*  -=><=- -=><=- -=><=- -=><=- -=><=- -=><=- -=><=- -=><=- -=><=-  */
  173.  
  174. /*
  175.  * The next macro should contain a list of characters LaTeX (and you?)
  176.  * considers as an small punctuation characters, which should not be
  177.  * preceded by a \/.
  178.  */
  179.  
  180. #define SMALL_PUNCT             ".,"
  181.  
  182.  
  183.  
  184. /*  -=><=- -=><=- -=><=- -=><=- -=><=- -=><=- -=><=- -=><=- -=><=-  */
  185.  
  186. /*
  187.  * NOTE: All macros below should return FALSE (0) if the input
  188.  * character is 0.
  189.  *
  190.  * The next macro should return TRUE if the character should be
  191.  * stripped from a string, e.g. if it is a space, tab, control
  192.  * character or any other `invisible' character.
  193.  *
  194.  */
  195.  
  196. #define SKIP_STRIP(c)   (c > 0 && c <= ' ')
  197.  
  198. /*  -=><=- -=><=- -=><=- -=><=- -=><=- -=><=- -=><=- -=><=- -=><=-  */
  199.  
  200. /*
  201.  * The next macro should return TRUE if LaTeX (and you?) considers
  202.  * the character `c' as a space, which should be detected when
  203.  * we're checking whether commands are terminated by spaces.
  204.  *
  205.  */
  206.  
  207. #define LATEX_SPACE(c)  (c > 0 && c <= ' ')
  208.  
  209.  
  210. /***************** END OF USER SETTABLE PREFERENCES *****************/
  211. /********************************************************************/
  212.  
  213. #if defined(HAVE_CONFIG_H) || defined(CONFIG_H_NAME)
  214. #   ifndef CONFIG_H_NAME
  215. #       define  CONFIG_H_NAME   "config.h"
  216. #   endif
  217. #   include CONFIG_H_NAME
  218. #   ifndef HAVE_VPRINTF
  219. #       error "Sorry, I need the vprintf function...please send info on doprnt"
  220. #   endif
  221. #endif
  222.  
  223. #include <ctype.h>
  224. #include <math.h>
  225. #include <stdio.h>
  226. #include <stdarg.h>
  227. #include <stddef.h>
  228. #include <stdlib.h>
  229.  
  230. #ifdef HAVE_UNISTD_H
  231. #   include <unistd.h>
  232. #endif
  233.  
  234. #ifdef HAVE_LIMITS_H
  235. #    include <limits.h>
  236. #else
  237. #    define LONG_MAX (0x7fffffff)
  238. #endif
  239.  
  240. #include <string.h>
  241.  
  242. #ifdef AMIGA
  243. #   include <exec/execbase.h>
  244. #   include "WB2Argv.h"
  245. #endif
  246.  
  247. #include "exec/types.h"
  248. #include "getopt.h"
  249.  
  250. #ifndef __NOPROTO
  251. #   ifndef __PROTO
  252. #       define __PROTO(a) a
  253. #   endif
  254. #else
  255. #   ifndef __PROTO
  256. #       define __PROTO(a) ()
  257. #   endif
  258. #endif
  259.  
  260.  
  261. /*
  262.  * How many indexes we'll allocate first time
  263.  */
  264. #define MINPUDDLE       256
  265.  
  266.  
  267. /*
  268.  * How many bytes we want in front/end of each UBYTE buffer.
  269.  */
  270.  
  271. #define WALLBYTES       2
  272.  
  273. #define betw(a,b,c)             ((a < b) && (b < c))
  274. #define within(a,b,c)   ((a <= b) && (b <= c))
  275. #define elif                    else if
  276.  
  277. #ifndef NOT
  278. #   define NOT(a)                   (!(a))
  279. #endif
  280. #define ifn(a)                  if(NOT(a))
  281.  
  282. #ifndef min
  283. #   define min(a,b) ((a)<=(b)?(a):(b))
  284. #endif
  285.  
  286. #ifndef max
  287. #   define max(a,b) ((a)>(b)?(a):(b))
  288. #endif
  289.  
  290. #ifndef abs
  291. #   define abs(a) (a>=0?a:(-a))
  292. #endif
  293.  
  294. #define QUOTE   '\"'    /* Char used to quote text containing blanks    */
  295. #define ESCAPE  '!'     /* Char used to access special characters       */
  296. #define CMNT    '#'     /* Char used as comment                         */
  297.  
  298.  
  299. #define STRP_LFT                        1
  300. #define STRP_RGT                        2
  301. #define STRP_BTH                        (STRP_LFT|STRP_RGT)
  302.  
  303. #define NUMBRACKETS             6
  304.  
  305. #define NEWBUF(name,len) \
  306. static \
  307. UBYTE   _##name         [len  + (WALLBYTES<<1)] = {0};  \
  308. const STRPTR    name =          &_##name[WALLBYTES]
  309.  
  310.  
  311. enum ErrNum
  312. {
  313.   emMinFault = 0,
  314.   emSpaceTerm, emNBSpace, emEnclosePar, emItInNoIt,
  315.   emItDup,  emNoItFound, emAccent,  emWrongDash,
  316.   emExpectC,  emSoloC,  emEllipsis,  emInterWord,
  317.   emInterSent, emNoArgFound, emNoMatchC,  emMathStillOn,
  318.   emNoMatchCC, emUseQuoteLiga, emUseOtherQuote,emUserWarn,
  319.   emNotIntended, emComment,  emThreeQuotes, emFalsePage,
  320.   emEmbrace,  emSpacePunct, emNoCmdExec, emItPunct,
  321.   emUseTimes, emMultiSpace, emIgnoreText, emBeginQ,
  322.   emEndQ, emQuoteMix, emWordCommand,
  323.   emMaxFault
  324. };
  325.  
  326. enum PrgErrNum {
  327.   pmMinFault = 0,
  328.  
  329.   pmUnknownTerm, pmNoFileMatch, pmNoTeXOpen, pmRename,
  330.   pmRenameErr, pmOutOpen,  pmOutTwice,  pmStrDupErr,
  331.   pmWordListErr, pmNoStackMem, pmWarnNumErr, pmVerbLevErr,
  332.   pmNotPSDigit, pmEscCode,  pmKeyWord,  pmFaultFmt,
  333.   pmRsrcOpen, pmSlowAbbr, pmEmptyToken, pmAssert,
  334.   pmNoRsrc,
  335.  
  336.   pmMaxFault,
  337. };
  338.  
  339. enum Context {
  340.     ctNone    = 0x00,
  341.     ctInMath  = 0x01,
  342.     ctOutMath = 0x02,
  343.     ctInHead  = 0x04,
  344.     ctOutHead = 0x08
  345. };
  346.  
  347. struct  ErrMsg {
  348.     enum ErrNum   Number;
  349.     enum {
  350.         etMsg,
  351.         etWarn,
  352.         etErr
  353.     }             Type;
  354.  
  355.     BOOL  InUse;
  356.     /* Requirements posed upon environment */
  357.     enum Context Context;
  358.  
  359.     STRPTR        Message;
  360. };
  361.  
  362. struct Stack {
  363.   APTR  *Data;
  364.   ULONG Size, Used;
  365. };
  366.  
  367. struct WordList {
  368.     struct Stack  Stack;
  369.     BOOL          Sorted;
  370. };
  371.  
  372. struct ErrInfo {
  373.   STRPTR
  374.         Data,
  375.         LineBuf,
  376.         File;
  377.   ULONG Line,
  378.   Column,
  379.   ErrLen;
  380. };
  381.  
  382. enum ItState {
  383.   itOff,
  384.   itOn,
  385.   itCorrected
  386. };
  387.  
  388. enum DotLevel {
  389.   dtUnknown = 0x0,
  390.   dtCDots = 0x1,
  391.   dtLDots = 0x2,
  392.   dtDots = 0x4
  393. };
  394.  
  395. struct FileNode {
  396.   STRPTR        Name;
  397.   FILE  *fh;
  398.   ULONG Line;
  399. };
  400.  
  401. extern const STRPTR
  402.     ReadBuffer,
  403.     CmdBuffer,
  404.     TmpBuffer;
  405.  
  406. extern BOOL
  407.         AtLetter,  /* Whether `@' is a letter or not. */
  408.         InHeader,  /* Whether we're in the header */
  409.         VerbMode;  /* Whether we're in complete ignore-mode */
  410.  
  411. extern LONG
  412.         MathMode;  /* Whether we're in math mode or not    */
  413.  
  414.  
  415. extern UBYTE   ConfigFile[BUFSIZ];
  416.  
  417. extern struct WordList
  418.         Silent, Abbrev, SlowAbbrev, Linker, IJAccent, Italic,
  419.         ItalCmd, UserWarn, CmdLine, PostLink, WipeArg, VerbEnvir,
  420.         MathEnvir, MathRoman, TeXInputs, HyphDash, NumDash, WordDash,
  421.         CenterDots, LowDots, OutFormat;
  422.  
  423. extern STRPTR VerbClear, PrgName;
  424.  
  425. extern
  426. struct Stack
  427. CharStack,
  428. InputStack,
  429. EnvStack;
  430.  
  431. extern struct ErrMsg
  432.     LaTeXMsgs [emMaxFault + 1],
  433.     PrgMsgs [pmMaxFault + 1];
  434.  
  435. extern const
  436.     UBYTE BrOrder[NUMBRACKETS + 1];
  437.  
  438. extern
  439.     ULONG Brackets  [NUMBRACKETS];
  440.  
  441. extern enum TermType TermType;
  442.  
  443. extern
  444.   ULONG ErrPrint,  /* # errors printed */
  445.         WarnPrint, /* # warnings printed */
  446.         UserSupp;  /* # user suppressed warnings */
  447.  
  448. extern
  449. enum ItState
  450. ItState;
  451.  
  452. extern FILE *OutputFile, *InputFile;
  453.  
  454. extern STRPTR
  455.         OutputName,
  456.         PseudoInName,
  457.         Delimit;
  458.  
  459. extern
  460.     BOOL GlobalRC, WipeVerb, TicToc, BackupOut,
  461.          Quiet, LicenseOnly, UsingStdIn, InputFiles,
  462.          HeadErrOut;
  463.  
  464. extern
  465.     STRPTR
  466.         OutputFormat;
  467.  
  468.  
  469. void    AddBracket      __PROTO((UBYTE const));
  470. LONG    BrackIndex      __PROTO((UBYTE const));
  471.  
  472. FILE *  CurStkFile      __PROTO((struct Stack *));
  473. STRPTR  CurStkName      __PROTO((struct Stack *));
  474. ULONG   CurStkLine      __PROTO((struct Stack *));
  475.  
  476. BOOL    fexists         __PROTO((STRPTR Filename));
  477. STRPTR  FGetsStk        __PROTO((STRPTR Dest, ULONG len, struct Stack *stack));
  478. BOOL    FindErr         __PROTO((STRPTR const, ULONG const));
  479. void    FreeErrInfo     __PROTO((struct ErrInfo* ei));
  480.  
  481. STRPTR  GetLTXArg       __PROTO((STRPTR, STRPTR, const UBYTE));
  482.  
  483. BOOL    HasWord         __PROTO((STRPTR const, struct WordList *));
  484.  
  485. BOOL    InsertWord      __PROTO((STRPTR const, struct WordList *));
  486.  
  487. int     main            __PROTO((int argc, char **argv));
  488. UBYTE   MapChars        __PROTO((STRPTR *));
  489. UBYTE   MatchBracket    __PROTO((UBYTE const));
  490. STRPTR  MatchFileName   __PROTO((STRPTR String));
  491.  
  492. BOOL    OpenOut         __PROTO((void));
  493.  
  494. int     ParseArgs       __PROTO((int argc, char **argv));
  495. int     ParseBoolArg    __PROTO((BOOL *, STRPTR *));
  496. int     ParseNumArg     __PROTO((LONG *, LONG, STRPTR *));
  497. enum ErrNum
  498.         PerformCommand  __PROTO((STRPTR const, STRPTR));
  499. struct ErrInfo *
  500.         PopErr          __PROTO((struct Stack *Stack));
  501. void    PrintError      __PROTO((const  STRPTR,
  502.                                 const STRPTR, const LONG, const LONG,
  503.                                 const LONG, const enum ErrNum, ...));
  504. void    PrintPrgErr     __PROTO((enum PrgErrNum , ...));
  505. void    PrintStatus     __PROTO((ULONG));
  506. BOOL    PushChar        __PROTO((const UBYTE c, const ULONG Line,
  507.                                 const ULONG Column, struct Stack *Stk,
  508.                                 const STRPTR LineCpy));
  509. BOOL    PushErr         __PROTO((const STRPTR Data, const ULONG Line,
  510.                                 const ULONG Column, const ULONG ErrLen,
  511.                                 const STRPTR LineCpy, struct Stack *Stk));
  512. BOOL    PushFile        __PROTO((STRPTR, FILE *, struct Stack *));
  513. BOOL    PushFileName    __PROTO((STRPTR Name, struct Stack *stack));
  514.  
  515. void *  saferealloc     __PROTO((void *, size_t));
  516. void    strwrite        __PROTO((STRPTR To, STRPTR From, ULONG Len));
  517. BOOL    ReadRC          __PROTO((STRPTR const));
  518.  
  519. void    SetupVars       __PROTO((void));
  520. APTR    sfmemset        __PROTO((APTR to, int c, LONG n));
  521. int     ShiftArg        __PROTO((STRPTR *Argument));
  522. void    ShowIntStatus   __PROTO((void));
  523. APTR    StkPop          __PROTO((struct Stack *));
  524. BOOL    StkPush         __PROTO((const APTR, struct Stack *));
  525. APTR    StkTop          __PROTO((struct Stack *));
  526.  
  527. int     strafter        __PROTO((STRPTR Str, STRPTR Cmp));
  528. int     strinfront      __PROTO((STRPTR Str, STRPTR Cmp));
  529. STRPTR  strip           __PROTO((STRPTR, WORDBITS const));
  530. void    strrep          __PROTO((STRPTR, UBYTE const, UBYTE const));
  531. int     str_cmp         __PROTO((void const *, void const *));
  532.  
  533. void    tackon          __PROTO((STRPTR, const STRPTR));
  534. void    tictoc          __PROTO((void));
  535. struct ErrInfo *
  536.         TopChar         __PROTO((struct Stack *));
  537. struct ErrInfo *
  538.         TopErr          __PROTO((struct Stack *Stack));
  539.  
  540.  
  541.  
  542. #ifndef HAVE_STRMID
  543. #   define  strmid  mystrmid
  544.  
  545. WORD    mystrmid          __PROTO((const STRPTR source, STRPTR dest,
  546.                                 ULONG pos, LONG len));
  547. #endif
  548.  
  549. #ifndef  HAVE_STRUPR
  550. #   define  strupr  mystrupr
  551.  
  552. STRPTR  mystrupr          __PROTO((STRPTR));
  553. #endif
  554.  
  555. #ifndef  HAVE_STRDUP
  556. #   define  strdup  mystrdup
  557.  
  558. STRPTR  mystrdup          __PROTO((STRPTR const));
  559. #endif
  560.  
  561. #ifndef HAVE_STRCASECMP
  562. int strcasecmp(char* a, char* b);
  563. #endif
  564.  
  565.  
  566.